package com.oracle.lingshangejia.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.oracle.lingshangejia.R;
import com.oracle.lingshangejia.base.BaseActivity;
import com.oracle.lingshangejia.pickerview.TimePickerView;
import com.oracle.lingshangejia.pickerview.Util;
import com.oracle.lingshangejia.utils.FileUtil;
import com.oracle.lingshangejia.view.FullScreenDialog;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

//个人信息
public class InformationActivity extends BaseActivity implements View.OnClickListener {

    private RelativeLayout re_back;
    private RelativeLayout re_head;
    private RelativeLayout re_name,re_idCard,re_company,re_phone,re_sex,re_birth,re_permanent_type
            ,re_national;
    private List<String> list_permanent_type = new ArrayList<>();
    private List<String> list_national = new ArrayList<>();
    private TextView tv_permanent_type,tv_birth,tv_sex,tv_national;

    @Override
    public int intiLayout() {
        return R.layout.activity_information;
    }

    @Override
    public void initView() {

        re_back=findViewById(R.id.re_back);
        re_back.setOnClickListener(this);
        re_head = findViewById(R.id.re_head);
        re_head.setOnClickListener(this);
        re_name = findViewById(R.id.re_name);
        re_name.setOnClickListener(this);
        re_idCard = findViewById(R.id.re_idCard);
        re_idCard.setOnClickListener(this);
        re_company = findViewById(R.id.re_company);
        re_company.setOnClickListener(this);
        re_phone = findViewById(R.id.re_phone);
        re_phone.setOnClickListener(this);
        re_sex = findViewById(R.id.re_sex);
        re_sex.setOnClickListener(this);
        re_birth = findViewById(R.id.re_birth);
        re_birth.setOnClickListener(this);
        re_permanent_type = findViewById(R.id.re_permanent_type);
        re_permanent_type.setOnClickListener(this);
        tv_permanent_type = findViewById(R.id.tv_permanent_type);
        tv_birth = findViewById(R.id.tv_birth);
        tv_sex = findViewById(R.id.tv_sex);
        re_national = findViewById(R.id.re_national);
        re_national.setOnClickListener(this);
        tv_national = findViewById(R.id.tv_national);
    }

    @Override
    public void initData() {


        list_permanent_type.add("户籍");
        list_permanent_type.add("户籍1");
        list_permanent_type.add("户籍2");
        list_national.add("汉");
        list_national.add("回");
        list_national.add("满");
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){

            //返回键
            case R.id.re_back:

                finish();
                break;

            //修改头像
            case R.id.re_head:

               // showChangeHeadnDialog();
                openPhoto();
                break;

            //修稿姓名
            case R.id.re_name:

                startActivity(new Intent(this,ChangeInformationActivity.class)
                                .putExtra("type","0"));
                break;

            //修改性别
            case R.id.re_sex:

                showChangeSexnDialog();
                break;

            //修改出生日期
            case R.id.re_birth:

                Util.alertTimerPicker(this, TimePickerView.Type.YEAR_MONTH_DAY,"yyyy-MM-dd", date -> {

                    tv_birth.setText(date);
                });
                break;

            //身份证号
            case R.id.re_idCard:

                startActivity(new Intent(this,ChangeInformationActivity.class)
                        .putExtra("type","1"));
                break;

            //工作单位
            case R.id.re_company:

                startActivity(new Intent(this,ChangeInformationActivity.class)
                        .putExtra("type","2"));
                break;

            //本人电话
            case R.id.re_phone:

                startActivity(new Intent(this,ChangeInformationActivity.class)
                        .putExtra("type","3"));
                break;

            //常住类型
            case R.id.re_permanent_type:

                Util.alertBottomWheelOption(this, list_permanent_type, null, null
                        , (view, postion) -> tv_permanent_type.setText(list_permanent_type.get(postion))
                        ,null,1);
                break;

            //民族
            case R.id.re_national:

//                Util.alertBottomWheelOption(this, list_national, null, null
//                        , (view, postion) -> tv_national.setText(list_national.get(postion))
//                        ,null,1);

//                startActivity(new Intent(this,RollInActivity.class));

                startActivity(new Intent(this,SpecialManagementActivity.class));
                break;
        }
    }

    private FullScreenDialog dialog_changeHead;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PictureConfig.CHOOSE_REQUEST && resultCode == RESULT_OK){
            LocalMedia localMedia = PictureSelector.obtainMultipleResult(data).get(0);
            localMedia.getPath();
        }
    }

    //打开相册
    private void openPhoto(){
        PictureSelector.create(this)
                .openGallery(PictureMimeType.ofImage())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()/主题样式(不设置为默认样式) 也可参考demo values/styles下 例如：R.style.picture.white.style
                .maxSelectNum(1)// 最大图片选择数量 int
                .minSelectNum(1)// 最小选择数量 int
                .imageSpanCount(4)// 每行显示个数 int
                .previewImage(true)// 是否可预览图片 true or false
                .isCamera(true)// 是否显示拍照按钮 true or false
               // .imageFormat(PictureMimeType.PNG)// 拍照保存图片格式后缀,默认jpeg
                .setOutputCameraPath("/CustomPath")// 自定义拍照保存路径,可不填
                .withAspectRatio(1,1)
                .enableCrop(true)// 是否裁剪 true or false
                .compress(true)// 是否压缩 true or false
                .compressSavePath(FileUtil.getPath())//压缩图片保存地址
                .circleDimmedLayer(true)// 是否圆形裁剪 true or false
                .previewEggs(false)// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中) true or false
                .minimumCompressSize(100)// 小于100kb的图片不压缩
                .synOrAsy(true)//同步true或异步false 压缩 默认同步
                .isDragFrame(false)// 是否可拖动裁剪框(固定)
                .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
    }



  /*  private void showChangeHeadnDialog(){

        if (dialog_changeHead == null){

            dialog_changeHead = new FullScreenDialog(this);
            View view_changeHead = View.inflate(this,R.layout.dialog_change_head,null);
            dialog_changeHead.setDialogGravity(Gravity.BOTTOM);
            dialog_changeHead.setContentView(view_changeHead);
            dialog_changeHead.setWH(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            dialog_changeHead.setCanceledOnTouchOutside(false);
        }

        dialog_changeHead.show();
    }*/

    private FullScreenDialog dialog_changeSex;

    private void showChangeSexnDialog(){

        if (dialog_changeSex == null){

            dialog_changeSex = new FullScreenDialog(this);
            View view_changeSex = View.inflate(this,R.layout.dialog_change_head,null);
            dialog_changeSex.setDialogGravity(Gravity.BOTTOM);
            dialog_changeSex.setContentView(view_changeSex);
            dialog_changeSex.setWH(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            dialog_changeSex.setCanceledOnTouchOutside(false);

            TextView tv_one = view_changeSex.findViewById(R.id.tv_one);
            tv_one.setText("男");
            TextView tv_two = view_changeSex.findViewById(R.id.tv_two);
            tv_two.setText("女");
        }

        dialog_changeSex.show();
    }
}



















